package com.ys.erp.entity.data.bean;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.ys.erp.common.util.DateUtil;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.Getter;
import lombok.experimental.Accessors;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.HashMap;
import java.util.Map;

/**
 * @author minamiyama
 * @date 2025/5/27 15:40
 */
@Data
@Accessors(chain = true)
@TableName("t_mall_home_activity")
public class MallHomeActivity {
    /**
     * 主键ID
     */
    @TableId(value = "id", type = IdType.AUTO)
    private Long id;

    @TableField("no")
    private String no;

    /**
     * 活动类型
     */
    @TableField("activity_type")
    private String activityType;

    /**
     * 活动名称
     */
    @TableField("activity_name")
    private String activityName;

    /**
     * 开始时间
     */
    @TableField("start_time")
    private LocalDateTime startTime;

    /**
     * 结束时间
     */
    @TableField("end_time")
    private LocalDateTime endTime;

    /**
     * 活动位置
     */
    @TableField("location")
    private Integer location;

    /**
     * 状态
     */
    @TableField("status")
    private Integer status;

    /**
     * 员工ID
     */
    @TableField("emp_id")
    private Long empId;

    /**
     * 员工手机号
     */
    @TableField("emp_phone")
    private String empPhone;

    /**
     * 员工姓名
     */
    @TableField("emp_name")
    private String empName;


    @TableField("activity_status")
    private String activityStatus;

    @TableField("is_delete")
    private Integer isDelete;

    /**
     * 版本号
     */
    @TableField("version")
    private Integer version;

    /**
     * 创建时间
     */
    @TableField("create_time")
    private LocalDateTime createTime;

    /**
     * 更新时间
     */
    @TableField(value = "update_time", update = "now()")
    private LocalDateTime updateTime;

    @AllArgsConstructor
    @Getter
    public enum Enums {

        NOT_STARTED,
        ONGOING,
        ENDED


    }

    public static final Map<String, String> ENUM_MAP = new HashMap<>();

    static {
        ENUM_MAP.put(Enums.NOT_STARTED.toString(), "未开始");
        ENUM_MAP.put(Enums.ONGOING.toString(), "进行中");
        ENUM_MAP.put(Enums.ENDED.toString(), "已结束");
    }

    public String getActivityStatus(String startTimeStr, String endTimeStr) {
        LocalDateTime now = LocalDateTime.now();
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern(DateUtil.DATE_FORMAT_ONE);
        LocalDateTime startTime = LocalDateTime.parse(startTimeStr, formatter);
        LocalDateTime endTime = LocalDateTime.parse(endTimeStr, formatter);
        if (now.isBefore(startTime)) {
            return MallHomeActivity.Enums.NOT_STARTED.toString();
        } else if (now.isAfter(endTime)) {
            return MallHomeActivity.Enums.ENDED.toString();
        } else {
            return MallHomeActivity.Enums.ONGOING.toString();
        }
    }
}
